<template>
  <TitleCard :title="titleCard" :showMore="showMore">
    <template slot="rightOperation">
      <div class="btn-wrap">
        <a-button class="btn-item">
          <a
            href="../../../../../static/file/备案主体清单.xlsx"
            download="预审备案主体模板下载"
            target="view_window"
            >预审备案主体模板下载</a
          ></a-button
        >
        <a-button class="btn-item">
          <a
            href="../../../../../static/file/登记代理机构.xlsx"
            download="预审备案企业模板下载"
            target="view_window"
            >预审备案企业模板下载</a
          ></a-button
        >
      </div>
    </template>
    <div class="backStack-table-wrap">
      <div class="head-top-wrap">
        <Tip :tip="tip"></Tip>
      </div>
      <Table
        ref="table"
        :options="fields"
        :tableValue="tableValue"
        :customSlotOpt="slotOpt"
        :otherOpt="customOtherOpt"
        :rowSelection="null"
        @change="initTableValue"
        @actionClick="handlerActionClick"
      ></Table>
    </div>
    <AModal ref="modal" :customOpt="customModalOpt" @ok="handlerOk"></AModal>
    <RetUpload
      v-if="isShowModal"
      @cancel="cancel"
      @addSuccess="addSuccess"
      :row="row"
    ></RetUpload>
  </TitleCard>
</template>

<script>
import Table from '../../components/table/index.vue'
import AModal from '../../components/AModal'
import mixinsBackStack from '@/views/backstageSupport/mixins'
import Tip from '../../components/common/tip.vue'
import { fields, slotOpt } from './configs/configs'
import { getDataAnalysisList } from '@/api/dataAnalysis.js'
import RetUpload from './components/retUpload.vue'
// const baseUrl = process.env.VUE_APP_FILE_URL

export default {
  mixins: [mixinsBackStack],
  data() {
    return {
      slotOpt,
      fields,
      customOtherOpt: {
        pagination: {
          total: 0,
          pageNum: 1,
          pageSize: 10
        }
      },
      tableValue: [],
      defaultSearchParam: {},
      tip: '此处用于维护【预审备案企业】和【登记代理机构】供查询的数据库，每次重新上传，均做全量覆盖更新',
      isShowModal: false
    }
  },
  components: {
    Table,
    AModal,
    Tip,
    RetUpload
  },
  mounted() {
    this.initSearchParams() // 重置搜索的参数
    this.initTableValue()
  },
  methods: {
    async initTableValue() {
      try {
        this.loadingTable(true) // 开启表格的加载动画
        const { rows, total } = await getDataAnalysisList() // 请求表格数据接口
        const row = this.handlerDateFormat(rows) // 处理时间格式
        this.handlerResultMappings(rows) // 处理数据的映射关系
        this.tableValue = row
        this.customOtherOpt.pagination.total = total
        this.initSelectedRowIds() // 清空勾选的选项
      } catch (error) {
        this.$apiStatusHandler(99, error.msg) // 请求异常，则全局轻提示
      } finally {
        this.loadingTable(false)
      }
    },
    down(row) {
      const a = document.createElement('a')
      // a.href = baseUrl + row.fileVo.filePath
      a.href =  row.fileVo.filePath
      a.download = row.fileVo.fileName
      a.click()
    },
    retUplod(row) {
      this.row = row
      this.isShowModal = true
    },
    cancel() {
      this.isShowModal = false
    },
    addSuccess() {
      this.isShowModal = false
      this.initTableValue()
    },
  }
}
</script>
